<template>
  <div>
    <div class="box">
      <div @click="showFooter(data.flag)" class="item">
        <div class="left">{{data.airline_name}} {{data.flight_no}}</div>
        <div class="center">
          <div class="c_l">
            <p>{{data.dep_time}}</p>
            <span>{{data.org_airport_name}} {{data.org_airport_quay}}</span>
          </div>
          <div class="c_c">
            <div>{{apartTime}}</div>
          </div>
          <div class="c_r">
            <p>{{data.arr_time}}</p>
            <span>{{data.dst_city_name}} {{data.dst_airport_quay}}</span>
          </div>
        </div>
        <div class="right">
          <div>
            ￥
            <span>{{basePirce}}</span>起
          </div>
        </div>
      </div>
      <div v-if="data.flag" class="footer">
        <div class="tickets">
          <div class="left">低价推荐</div>
          <div class="name">
            <div class="right" v-for="(item,index) in data.seat_infos" :key="index">
              <div class="r_l">
                <span>{{item.name}}</span> |
                {{item.supplierName}}
              </div>
              <div class="price">￥{{item.par_price}}</div>
              <div class="select">
                
                <div class="btn" @click="sureBtn(item,data.id)">选定</div>
                <div v-if="item.nums!='A'" class="num">剩余：{{item.nums}}</div>
              </div>
            </div>

          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props:{
    data:{
      type:Object,
      default(){
        return{}
      }
    }
  },
  methods: {
    showFooter(flag){
      this.data.flag = !flag
    },
    sureBtn(item,id){
      this.$router.push({path:'/air/order',query:{
        id:id,
        seat_xid:item.seat_xid
      }})
    }
  },
  computed: {
    // 相隔时间
    apartTime(){
      const start  = this.data.dep_time.split(':')
      const end  = this.data.arr_time.split(':')
      let startMin = (start[0] * 60) + +start[1]
      let endMin = (end[0] * 60) + +end[1]
      if(endMin < startMin){
        endMin+=24*60
      }
      const hours = Math.floor((endMin-startMin) / 60);
      const mins = (endMin-startMin) % 60;

      return `${hours}小时${mins}分`

    },
    basePirce(){
      let arr = []
      this.data.seat_infos.forEach(x=>{
        arr.push(x.par_price)
      })
      return Math.min(...arr)
    }
  },
}
</script>
<style lang="less" scoped>
.box {
  margin-top: 10px;
  border: 1px solid #ddd;
}
.item {
  height: 81px;
  padding: 15px 50px;
  cursor: pointer;
  display: flex;

  .left {
    display: flex;
    align-items: center;
    // background:pink;
    font-size: 14px;
  }
  .center {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 0 90px;
    div {
      flex: 1;
      p {
        font-size: 26px;
      }
      span {
        font-size: 12px;
        color: #b3a6c4;
      }
    }
    .c_c {
      flex: none;
      margin-right: 30px;
      // background: pink;
      div {
        line-height: 30px;
        font-size: 14px;
        color: #a699a6;
        height: 70%;
        // background:red;
        border-bottom: 1px solid #ddd;
      }
    }
  }
  .right {
    display: flex;
    align-items: center;
    // background:pink;
    font-size: 14px;
    span {
      font-size: 26px;
      color: #ffa500;
    }
  }
}
.footer {
  background: #f6f6f6;
  border-top: 1px solid #eeeeee;

  .tickets {
    display: flex;
    .left {
      width: 116px;
      padding: 0 20px;
      display: flex;
      align-items: center;
      font-size: 14px;
    }
    .name {
      flex: 1;
      // display: flex;
      .right {
        // flex: 1;
        // background: red;
        height: 72px;
        display: flex;
        align-items: center;
        .r_l {
          flex: 1;
          // background:orange;
          font-size: 12px;
          span {
            color: green;
          }
        }
        .price {
          font-size: 22px;
          color: #ffa500;
          margin-right: 50px;
        }
        .select {
          margin-right: 20px;
          .btn {
            padding: 6px 20px;
            border-radius: 3px;
            font-size: 12px;
            background: #e6a23c;
            color: #fff;
            cursor: pointer;
            margin-bottom: 4px;
          }
          .num {
            font-size: 14px;
            color: #666666;
            text-align: center;
          }
        }
      }
    }
  }
}
</style>